package ink.lovejinhu.leetcode;

/**
 * @Author: jin
 * @Date: 2021/9/7 12:27
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0868 {
    public int binaryGap(int n) {
        String s = Integer.toBinaryString(n);
        System.out.println(s);
        /**
         * 寻找两个相邻1之间的最大距离
         */
        int start = -1;
        int end = -1;
        int max = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '1') {
                if (start == -1) {
                    start = i;
                    continue;
                }
                if (end == -1) {
                    end = i;
                    max = end - start;
                    continue;
                }
                start = end;
                end = i;
                if (end - start > max) {
                    max = end - start ;
                }
            }
        }
        return max;

    }

    public static void main(String[] args) {
        Solution_0868 solution_0868 = new Solution_0868();
        solution_0868.binaryGap(13);
    }
}
